from PyQt4.QtCore import *
from PyQt4.QtGui import *

from common import *
from mapeditor.core.memanager import MEManager
from common.GLUtil.camera import Camera
from common.GLUtil.mouse import Mouse
from common.GLUtil.lighting import Lighting

class GlScrollArea(QAbstractScrollArea):
	"""
	Implementation of the QAbstractScrollArea widget
	applied to the GlWidget camera.
	"""
	def __init__ (self, parent):
		"""
		Widget constructor.
		"""
		
		super(GlScrollArea, self).__init__(parent)
		self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
		self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
		#self.setCornerWidget()
		
		# Initialize scrollbar-related attributes.
		self.horizontalScrollBar().setRange(0, MEManager.map.terrain.width)
		self.verticalScrollBar().setRange(0, MEManager.map.terrain.height)

	def scrollContentsBy(self, dx, dy):
		"""
		Scrollbars movement callback.
		"""
		
		MEManager.camera.position += (dx * 0.5) * MEManager.camera.leftVector
		MEManager.camera.position += (dy * 0.5) * MEManager.camera.upVector
		MEManager.updateGL()